﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace EmProductCenter
{
    public partial class Login : System.Web.UI.Page
    {
        BLL.ePioneer_UserInfo bllEPUI = new BLL.ePioneer_UserInfo();
        Common.CommonClass common = new Common.CommonClass();
        protected void Page_Load(object sender, EventArgs e)
        {
            string strAction = Request["action"].ToString();
            StringBuilder strReturn = new StringBuilder();
            switch (strAction)
            {
                //登录
                case "GoLogin":
                    strReturn = GoLogin();
                    break;
                case "Logout":
                    Session["LoginName"] = null;
                    strReturn.Append(0);
                    break;
            }
            Response.Write(strReturn);
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <returns>0:登录成功！1:用户名不存在，请先注册！2:密码错误！</returns>
        public StringBuilder GoLogin()
        {
            StringBuilder strReturn = new StringBuilder();
            string loginName = "", passWord = "";
            if (Request["loginName"] != null && Request["loginName"] != "")
                loginName = Request["loginName"];
            if (Request["passWord"] != null && Request["passWord"] != "")
                passWord = Request["passWord"];
            string returnStr = bllEPUI.Login(loginName, passWord);
            if (returnStr == "0")
            {
                Session["LoginName"] = loginName;
            }
            string[] ss = new string[] { returnStr, loginName };
            strReturn.AppendLine(common.ObjToJson(ss, Encoding.UTF8));
            return strReturn;
        }
    }
}